import random
def generate_lottery_number():
    """生成一注彩票号码（8 个 1-33 的随机整数）"""
    return sorted(random.sample(range(1, 34), 8))
def check_prize(winning_numbers, user_numbers):
    """
    检查用户号码与中奖号码的匹配情况，返回中奖等级：
    - 全对：一等奖
    - 错一个：二等奖
    - 错两个：三等奖
    - 错三个：四等奖
    - 其他：未中奖
    """
    matched = sum(1 for num in user_numbers if num in winning_numbers)
    if matched == 8:
        return "一等奖"
    elif matched == 7:
        return "二等奖"
    elif matched == 6:
        return "三等奖"
    elif matched == 5:
        return "四等奖"
    else:
        return "未中奖"

def simulate_lottery(target_numbers, num_tickets=10000):
    """
    模拟购买彩票并统计中奖概率：
    - target_numbers: 特定号码
    - num_tickets: 购买的彩票数量
    """
    prize_counts = {
        "一等奖": 0,
        "二等奖": 0,
        "三等奖": 0,
        "四等奖": 0,
        "未中奖": 0
    }

    for _ in range(num_tickets):
        lottery_numbers = generate_lottery_number()
        prize = check_prize(target_numbers, lottery_numbers)
        prize_counts[prize] += 1

    # 输出中奖概率
    print(f"模拟购买 {num_tickets} 注彩票的中奖概率：")
    for prize, count in prize_counts.items():
        probability = count / num_tickets * 100
        print(f"{prize}: {probability:.2f}%")

def main():
    # 生成中奖号码
    winning_numbers = generate_lottery_number()
    print("本期中奖号码：", winning_numbers)

    # 用户输入
    user_input = input("请输入 8 个数字（1-33），用空格分隔：")
    user_numbers = list(map(int, user_input.split()))

    # 检查中奖
    prize = check_prize(winning_numbers, user_numbers)
    print("中奖结果：", prize)

    # 模拟购买 10000 注彩票
    simulate_lottery(winning_numbers)

if __name__ == "__main__":
    main()